// pages/newmore/newmoreDetail/newmoreDetail.js
var utils = require('../../../utils/util.js');
var WxParse = require('../../../wxParse/wxParse.js');  
var httpUrl = getApp().globalData.httpUrl;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        isStart:false,
        isZan:false
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that=this;
        that.setData({
            id:options.id,
            type:options.type
        })
        var url="";
        //首页新闻
        if (options.type == 1) {
            url ="/mobile/notice/detail";
        } 
        //热推新闻
        if (options.type == 2) {
            url ="/mobile/article/article_detail";
        }
        if (options.type == 4) {
            url = "/mobile/coach/article_detail";
        }
        if (options.type == 5) {
            url = "/mobile/member/my_person_article_detail";
        }
        if (options.type == 6) {
            url = "/mobile/member/my_teacher_article_detail";
        }
        utils.showLoading();
        utils.http(httpUrl+url, {id:options.id}, function (res) {
            utils.hideLoading();
            if (res.state == 1) {
                WxParse.wxParse('article', 'html', res.datas.content, that, 5);
                if (res.datas.my_is_col==1){
                    that.setData({
                        isStart: true
                    })
                }else{
                    that.setData({
                        isStart: false
                    })
                }
                if (res.datas.my_is_zan == 1) {
                    that.setData({
                        isZan: true
                    })
                } else {
                    that.setData({
                        isZan: false
                    })
                }
                that.setData({
                    data: res.datas,
                    dataTime:res.datas.create_time.substring(0, 10)
                });
            } else {
                utils.message(res.datas);
                wx.showModal({
                    title: '温馨提示',
                    content: res.datas,
                    showCancel:false,
                    success(res) {
                        if (res.confirm) {
                            wx.navigateBack({
                                delta: 1
                            })
                        } 
                    }
                })
            }
        })
    },
    //详情收藏
    oNstrartTap:function(e){
        var that=this;
        utils.http(httpUrl + "/mobile/common/make_col", { be_id: this.data.id, type:that.data.type }, function (res) {
            if (res.state == 1) {
                that.data.isStart = !that.data.isStart
                that.setData({
                    state: res.state,
                    isStart: that.data.isStart
                })
                console.log(that.data.isStart)
                utils.message(res.datas);
            } else {
                utils.message(res.datas);
            }
        })
    },

    //详情点赞
    oNzanTap: function (e) {
        var that = this;
        utils.http(httpUrl + "/mobile/common/make_zan", { be_id: this.data.id, type: that.data.type}, function (res) {
            console.log(res);
            if (res.state == 1) {
                that.data.isZan = !that.data.isZan
                that.setData({
                    state: res.state,
                    isZan: that.data.isZan
                })
                console.log(that.data.isZan)
                utils.message(res.datas);
            } else {
                utils.message(res.datas);
            }
        })
    },
})